{if $parentID}
	{assign var="fieldID" value=$form_field.id}
{else}
	{assign var="fieldID" value=$id}
{/if}
{literal}
<script type="text/javascript">

	$(document).ready(function(){

	function liFormat (row, i, num) {
		var result = row[0];
		return result;
	}

	function selectItem(li) {
		if( li == null ) var sValue = 'Nothing Selected!';
		if( !!li.extra ) var sValue = li.extra[2];
		else var sValue = li.selectValue;
		alert("Selected ID: " + sValue);
	}

	{/literal}
		var elementId     = "{if $parentID}{$parentID}_{$fieldID}{else}{$fieldID|replace:':':'\\\\:'}{/if}";

		var siteUrl       = "{$GLOBALS.site_url}/autocomplete/";
		var field         = "{if $complexField}{$complexField}:{elseif $parentID}{$parentID}_{/if}{$fieldID}/";
		var fieldType     = "{if $form_fields.$fieldID.type}{$form_fields.$fieldID.type}{elseif $theField.type}{$theField.type}{else}text{/if}/";
		var tablePrefix   = "{if $form_fields.$fieldID.is_classifieds == 1 || $theField.is_classifieds == 1}listings{else}users{/if}/";
		var viewType      = "{$parameters.viewType}/";
		var listingTypeID = "{if $listingTypeID}{$listingTypeID}{else}Job{/if}/";
		var isComplex     = "{if ($theField && $theField.type != 'location') || $complexField}1/{else}0/{/if}";
	{literal}

	$("input#" + elementId).autocomplete(siteUrl + field + fieldType + tablePrefix + viewType + listingTypeID + isComplex, {
		delay:10,
		minChars:{/literal}{if $GLOBALS.settings.min_autocomplete_symbols_quantity}{$GLOBALS.settings.min_autocomplete_symbols_quantity}{else}1{/if}{literal},
		matchSubset:1,
		autoFill:false,
		width: 300,
		matchContains:1,
		cacheLength:1,
		selectFirst:true,
		formatItem:liFormat,
		maxItemsToShow:5,
		onItemSelect:selectItem
		})
	}); 

</script>
{/literal}